// let a:string = 'Hello World'
// console.log(a)
// let arr1:number[] = [1,3]
// let arr2:Array<number> = [1,5]
// function buildName(firstName:string,...restName:string[]):string{
//     return firstName +' '+ restName.join(' ')
// }
// let buNa = buildName('Richard','Ann','Jane','Mike')
// console.log(buNa)
// let buNam :(fName:string,...restN:string[])=>string = buildName
// let bN = buNam('Richard','Ann','Jane','Mike','Marial')
// console.log(bN)

// ??函数
// 函数this 指向问题
// interface Card {
//     suit :string;
//     card:number;
// }
// interface Deck {
//     suits:string[];
//     cards:number[];
//     createCardPicker(this:Deck):()=>Card;
// }

// let deck: Deck= {
//         suits:['Richard','Ann','Jane','Mike','Nick'],
//         cards:Array(52),
//         createCardPicker:function(this:Deck){
//             return ()=>{
//                 let PickedCard = Math.floor(Math.random()*52)
//                 let PickedSuit = Math.floor(PickedCard/13)
//                 return {suit:this.suits[PickedSuit],card:PickedCard%13}
//             }
//         }

// }
// let ca = deck.createCardPicker()
// let ayou = ca() 
// console.log(ayou)

// 函数重载
// let suits = ['Richard','Ann','Jane','Mike','Nick']
// function pickCard (x:{suit:string,card:number}[]):number;
// function pickCard (x:number):{suit:string,card:number}
// function pickCard(x:any):any{
//     if(typeof x == 'object'){
//         let pickedCard = Math.floor(Math.random() * x.length);
//         return pickedCard;
//     }else if(typeof x=='number'){
//         let pickedSuit = Math.floor(x / 13);
//         return { suit: suits[pickedSuit], card: x % 13 };
//     }
// }
// let myDeck = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }];
// let pickedCard1 = myDeck[pickCard(myDeck)];
// console.log("card: " + pickedCard1.card + " of " + pickedCard1.suit)
// let pickedCard2 = pickCard(15)
// console.log("card: " + pickedCard2.card + " of " + pickedCard2.suit)

// 类 继承
// class Animal {
//     name: string;
//     constructor(theName: string) { this.name = theName; }
//     move(distanceInMeters: number = 0) {
//         console.log(`${this.name} moved ${distanceInMeters}m.`);
//     }
// }

// class Snake extends Animal {
//     constructor(name: string) { super(name); }
//     move(distanceInMeters = 5) {
//         console.log("Slithering...");
//         super.move(distanceInMeters);
//     }
// }

// class Horse extends Animal {
//     constructor(name: string) { super(name); }
//     move(distanceInMeters = 45) {
//         console.log("Galloping...");
//         super.move(distanceInMeters);
//     }
// }

// let sam = new Snake("Sammy the Python");
// let tom: Animal = new Horse("Tommy the Palomino");

// sam.move();
// tom.move(34);

// 公共，私有与受保护的修饰符

// class Animal {
//    private name:string;
//     constructor(theName:string){
//         this.name = theName
//     }
// }
// console.log(new Animal('houhou').name)

/******************类型兼容******************** */
// class Animal {
//     name:string;
//     // private name: string;
//     age:number;
//     private gender:string;
//     constructor(theName: string,theAge:number) { this.name = theName;this.age =theAge,this.gender='N' }
//     moveing(){
//         console.log('gender'+this.gender)
//     }
// }

// class Rhino extends Animal {
//     constructor() { super("Rhino",20); }
//     move(){
//     // console.log('gender'+this.gender)
//     }

// }

// class Employee {
//     name:string;
//     age:number;
//     // private name: string;
//     constructor(theName: string,theAge:number) { this.name = theName;this.age =theAge}
// }

// let animal = new Animal("Goat",17);
// let rhino = new Rhino();
// let employee = new Employee("Bob",10);
// animal = rhino

// animal.moveing()
// rhino.move()
// console.log(animal = rhino)
// console.log(animal = employee)

// ?? 存取器
/******************存取器********************* */
// let passcode = "secret1 passcode";

// class Employee {
//     private _fullName:string ='xx';

//     get fullName(): string {
//         return this._fullName;
//     }

//     set fullName(newName: string) {
//         if (passcode && passcode == "secret passcode") {
//             this._fullName = newName;
//         }
//         else {
//             console.log("Error: Unauthorized update of employee!");
//         }
//     }
// }

// let employee = new Employee();
// employee.fullName = "Bob Smith";
// if (employee.fullName) {
//     console.log(employee.fullName);
// }
// // 静态属性 
// class Grid{
//     static origin ={x:0,y:0}
//     countNum(point:{x:number,y:number}){
//         let xDist = (point.x-Grid.origin.x)
//         let yDist = (point.y-Grid.origin.y)
//         return Math.sqrt(xDist*xDist+yDist*yDist)/this.scale
//     }
//     constructor(public scale:number){}
// }
// let grid1 = new Grid(1.0)
// let grid2= new Grid(5.0)
// console.log(grid1.countNum({x:10,y:10}))
// console.log(grid2.countNum({x:10,y:10}))



// 抽象类
// class Greeter {
//     static standardGreeting = "Hello, there";
//     greeting: string='';
//     greet() {
//         if (this.greeting) {
//             return "Hello, " + this.greeting;
//         }
//         else {
//             return Greeter.standardGreeting;
//         }
//     }
// }

// let greeter1: Greeter;
// greeter1 = new Greeter();
// console.log(greeter1.greet());

// let greeterMaker: typeof Greeter = Greeter;
// greeterMaker.standardGreeting = "Hey there!";

// let greeter2: Greeter = new greeterMaker();
// console.log(greeter2.greet());
// class Point {
//     x: number=0;
//     y: number=0;
// }

// interface Point3d extends Point {
//     z: number;
// }

// let point3d: Point3d = {x: 1, y: 2, z: 3};

//!!泛型最后的例子 没看懂
//泛型
// function create<T>(c:{new():T}):T{
//     return new c()
// }
// class BeeKeeper {
//     hasMask: boolean;
// }

// class ZooKeeper {
//     nametag: string;
// }

// class Animal {
//     numLegs: number;
// }

// class Bee extends Animal {
//     keeper: BeeKeeper;
// }

// class Lion extends Animal {
//     keeper: ZooKeeper;
// }

// function createInstance<A extends Animal>(c: new () => A): A {
//     return new c();
// }

// createInstance(Lion).keeper.nametag;  // typechecks!
// createInstance(Bee).keeper.hasMask;   // typechecks!


